import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import schedule
import time

# 配置邮件信息
sender_email = "your_email@example.com"
receiver_email = "recipient_email@example.com"
password = "your_email_password"

# 创建邮件对象
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = "定时邮件"

# 添加邮件正文
body = "目前数据"
message.attach(MIMEText(body, "plain"))

# 添加本地照片作为附件
with open("local_photo.jpg", "rb") as file:
    img = MIMEImage(file.read())
    img.add_header("Content-Disposition", "attachment", filename="local_photo.jpg")
    message.attach(img)

# 定义发送邮件的函数
def send_email():
    try:
        server = smtplib.SMTP("smtp.example.com", 587)
        server.starttls()
        server.login(sender_email, password)
        text = message.as_string()
        server.sendmail(sender_email, receiver_email, text)
        server.quit()
        print("邮件发送成功")
    except Exception as e:
        print(f"邮件发送失败: {e}")

# 定时任务，每天的10:00发送邮件
schedule.every().day.at("10:00").do(send_email)

while True:
    schedule.run_pending()
    time.sleep(1)